import datetime
import requests
import pandas as pd
import pymysql
from sklean.preprocessing import MinMaxScaler
from joblib import dump 
 
class WeatherUtils(object):
    def __init__(self):
        self.url = 'http://v1.yiketianqi.com/api'
        self.date = [
            '2024-07-01',
            '2024-08-01',
            '2024-09-01',
            '2024-10-01',
            '2024-11-01',
            '2024-12-01',
        ]

    def get_data(self):
        data_list = []
        for d in self.data:
            conf = {
                'appid':'88249599',
                'appsecret':'BA7zIjrM',
                'version':'history',
                'year':d[:4],
                'month':d[5:7],
                'city':'南昌'
            }
        res = requests.get(self.url + '?', params=conf)
        res_data = res.json()
        for i in res_data['data']:
            data_list.append({
                'data':datetime.date.strftime(i['ymd'],'%Y-%m-%d'),
                'bWendu':i['bWendu'],
                'yWendu':i['yWendu'],
                'tianqi':i['tianqi'],
                'fengxiang':i['fengxiang'],
                'fengli':i['fengli'],
            })
        df = pd.DataFrame(data_list)
        df.to_csv('./timing/weather.csv')


if __name__ == '__main__':
    wu = WeatherUtils()
    wu.get_data()